import { withResolvers } from '@/utils/promise.utils';

// 路由白名单
const WHITE_LIST: NavigateToOptions['url'][] = [
];

console.log('>>>WHITE_LIST', WHITE_LIST);

// 黑名单登录拦截器
const navigateToInterceptor = {
  // 注意，这里的url是 '/' 开头的，如 '/pages/index/index'，跟 'pages.json' 里面的 path 不同
  invoke(args: { url: string }) {
    const { promise, resolve } = withResolvers<any>();

    setTimeout(() => {
      console.log('>>>>', args);

      resolve(args);
    }, 100);

    return promise;
  }
};

export const routeInterceptor = {
  install() {
    uni.addInterceptor('navigateTo', navigateToInterceptor);
    uni.addInterceptor('reLaunch', navigateToInterceptor);
    uni.addInterceptor('redirectTo', navigateToInterceptor);
    uni.addInterceptor('switchTab', navigateToInterceptor);
  }
};
